package threadcoreknowledge.stopthreads;

public class RightWayStopThreadWithoutSleep implements Runnable {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new RightWayStopThreadWithoutSleep());
        t.start();
        Thread.sleep(1000);
        t.interrupt();
    }


    @Override
    public void run() {
        int num = 0;
        while (!Thread.currentThread().isInterrupted() && num <= Integer.MAX_VALUE / 2) {
            if (num % 10000 == 0) System.out.println(num);
            num++;
        }
        System.out.println("任务结束");
    }
}
